<template lang="html">
  <div class="page">
    <cube-scroll ref="scroll" :data="list" :options="opts" @pulling-down="onPullingDown">
      <list :is-empty="!list.length">
        <item :img-src="item.CoverImage"
        v-for="(item,index) in list" :key="index"
        :title="item.Title"
        :desc="item.Summary"
        :href="'/home/detail/' + item.Id">
          <div class="text-footer" slot="text-footer">所属单位：{{item.DeptName}}</div>
          <div class="label" slot="label"> 待处理 </div>
        </item>
      </list>
    </cube-scroll>
  </div>
</template>

<script>
export default {
  data(){
    return {
      list:[],
      obj:{},
      opts:{
        scrollbar:{
          fade: true
        },
        pullDownRefresh: {
          threshold: 90,
          stop: 40,
          txt: '刷新成功'
        }
      }
    }
  },
  created () {
    //this.getListData();
    this.getList();
  },
  methods : {
    getList() {
      this.$http.post("app/Handler/DispatchHandler.ashx?action=GetTodoList")
      .then(data => {
        console.log(data);
        if(data.code == 0){
          this.list = data.data;
        }
      })	 
    },
    getListData() {
      this.id = this.$route.query.id
      this.axios.get('https://jason588.github.io/data.json').then((res) => {
        this.list = res.data.List
        this.obj = res.data.List[this.id]
      })
    },
    onPullingDown() {
      // 模拟更新数据
      setTimeout(() => {
        if (Math.random() > 0.5) {
          this.$createToast({
            time: 1000,
            txt: '正在加载新数据'
          }).show()
        } else {
          // 如果没有新数据
          this.$refs.scroll.forceUpdate()
        }
      }, 1000)
    }

  },
}
</script>

<style lang="stylus">
@import "assets/stylus/base"
</style>
